<template>
  <div>
    <!-- 水泥混凝土 -->
    <template v-if="trialNum == $trialNum.SNHNT">
      <a-select
        allowClear
        placeholder="请选择设计强度"
        v-model="form.strengthGrade"
        @change="changeSelect"
      >
        <a-select-option
          :value="v"
          v-for="(v, i) in designStrengthList"
          :key="i"
        >
          {{ v }}
        </a-select-option>
      </a-select>
      <a-select
        allowClear
        placeholder="请选择养护龄期"
        v-model="form.curingAge"
        @change="changeSelect"
      >
        <a-select-option
          :value="v.dicValue"
          v-for="v in curingAges"
          :key="v.id"
        >
          {{ v.dicDesc }}
        </a-select-option>
      </a-select>
    </template>
    <a-select
      placeholder="请选择结果判定"
      allowClear
      v-model="selectData.result"
      @change="changeSelect"
    >
      <a-select-option :value="v.value" v-for="v in resultList" :key="v.value">
        {{ v.name }}
      </a-select-option>
    </a-select>
  </div>
</template>
<script>
import {
  trialInfo,
  snInfo,
  lqInfo,
  lqmxeInfo,
} from "@/api/wisdom-beam/trial-app";
export default {
  props: {
    trialNum: {
      type: String,
    },
    select: {
      type: Boolean,
      default: false,
    },
  },
  watch: {
    trialNum: {
      handler(val) {
        this.trialInfo();
      },
      immediate: true,
    },
  },
  data() {
    return {
      form: {
        strengthGrade: undefined, //设计强度
        curingAge: undefined, //养护龄期
        kind: undefined, //水泥品种
        brand: undefined, //牌号
        nominalDiameter: undefined, //公称直径
        lqType: undefined, //沥青名称
        asphaltNum: undefined, //沥青类别
        asphaltLevel: undefined, //沥青等级
        weatherRegion: undefined, //气候分区
        temperature: undefined, //延度温度值
        mxeType: undefined, //沥青混合料种类
        roadLevel: undefined, //公路等级
        trafficType: undefined, //交通路段分类
        designStrength: undefined, //设计强度
        surface: undefined, //结构层
      },
      designStrengthList: [],
      curingAges: [],
      kinds: [],
      brandsList: [],
      nominalDiametersList: [],
      lqTypesList: [],
      asphaltNumList: [],
      asphaltLevelList: [],
      weatherRegionList: [],
      lqTemperaturesList: [],
      mxeTypeList: [],
      roadLevelList: [],
      trafficTypeList: [],
      designStrengths: [],
      gcjcMxeTypes: [],

      selectData: {
        result: undefined,
        dataSource: undefined,
      },
      resultList: [
        {
          name: "合格",
          value: 0,
        },
        {
          name: "不合格",
          value: 1,
        },
        {
          name: "试验数据无效",
          value: 2,
        },
        {
          name: "实测",
          value: -1,
        },
      ],
      dataSourceList: [
        {
          name: "手动录入",
          value: 0,
        },
        {
          name: "物联网数据",
          value: 1,
        },
      ],
    };
  },
  methods: {
    // 试验信息
    trialInfo() {
      trialInfo({
        trialNum: this.trialNum,
      })
        .then((res) => {
          let {
            data: { result },
          } = res;
          this.designStrengthList = result.strengthGrades || [];
          this.curingAges = result.curingAges || [];
          this.kinds = result.kinds || [];
          this.brandsList = result.brands || [];
          this.nominalDiametersList = result.nominalDiameters || [];
          this.lqTypesList = result.lqTypes || [];
          this.lqTemperaturesList = result.lqTemperatures || [];
          this.designStrengths = result.designStrengths || [];
          this.surfaces = result.surfaces || [];
          this.gcjcMxeTypes = result.gcjcMxeTypes || [];
          if (this.trialNum == this.$trialNum.LQWL) {
            this.lqInfo(1);
          }
          //   if (this.select) {
          //     this.form.strengthGrade = this.designStrengthList[0] || "";
          //     this.form.curingAge = this.curingAges[0].dicValue || "";
          //     // // 水泥混凝土
          //     // if (this.trialNum == this.$trialNum.SNHNT) {
          //     //   this.form.strengthGrade = this.designStrengthList[0];
          //     //   this.form.curingAge = this.curingAges[0].dicValue;
          //     // }
          //     // 水泥
          //     if (this.trialNum == this.$trialNum.SN) {
          //       this.form.kind = this.kinds[0];
          //       this.changeKind();
          //     }
          //     // 钢筋原材、钢筋焊接接头、钢筋机械连接接头
          //     if (
          //       this.trialNum == this.$trialNum.GJYC ||
          //       this.trialNum == this.$trialNum.GJHJ ||
          //       this.trialNum == this.$trialNum.GJLJ
          //     ) {
          //       this.form.brand = this.brandsList[0];
          //       this.form.nominalDiameter = this.nominalDiametersList[0].dicValue;
          //     }
          //     // 沥青原材
          //     if (this.trialNum == this.$trialNum.LQWL) {
          //       this.form.temperature = this.lqTemperaturesList[0].dicValue;
          //     }
          //     // 沥青混合料
          //     if (this.trialNum == this.$trialNum.LQHHL) {
          //       this.form.lqType = this.lqTypesList[0].dicValue;
          //       this.changeLqType(this.form.lqType);
          //     }
          //     // 无机结合料
          //     if (this.trialNum == this.$trialNum.WJJHL) {
          //       this.form.designStrength = this.designStrengths[0];
          //     }
          //     // 工程检测
          //     if (this.trialNum == this.$trialNum.GCJC) {
          //       this.form.surface = this.surfaces[0].dicValue;
          //       this.form.mxeType = this.gcjcMxeTypes[0].dicValue;
          //     }
          //   }
        })
        .catch((_) => {});
    },
    // 沥青马歇尔信息
    lqmxeInfo(type, lqType, mxeType, roadLevel, trafficType) {
      lqmxeInfo({
        trialNum: this.trialNum,
        lqType,
        mxeType,
        roadLevel,
        trafficType,
      })
        .then((res) => {
          let {
            data: { result },
          } = res;
          if (type == 1) {
            this.mxeTypeList = result || [];
            // if (this.select) {
            //   this.form.mxeType = this.mxeTypeList[0];
            //   this.changeMxeType(this.form.mxeType);
            // }
          }
          if (type == 2) {
            this.roadLevelList = result || [];
            // if (this.select) {
            //   this.form.roadLevel = this.roadLevelList[0];
            //   this.changeRoadLevel(this.form.roadLevel);
            // }
          }
          if (type == 3) {
            this.trafficTypeList = result || [];
            // if (this.select) {
            //   this.form.trafficType = this.trafficTypeList[0];
            //   this.changeTrafficType(this.form.trafficType);
            // }
          }
          if (type == 4) {
            this.weatherRegionList = result || [];
          }
        })
        .catch((_) => {});
    },

    // 沥青名称切换，获取沥青类别列表
    changeLqType(value) {
      this.form.mxeType = undefined;
      this.form.roadLevel = undefined;
      this.form.trafficType = undefined;
      this.form.weatherRegion = undefined;
      this.changeSelect();
      if (value) {
        this.lqmxeInfo(1, value);
      }
    },
    // 沥青混合料种类切换，获取公路等级列表
    changeMxeType(value) {
      this.form.roadLevel = undefined;
      this.form.trafficType = undefined;
      this.form.weatherRegion = undefined;
      this.changeSelect();
      if (value) {
        this.lqmxeInfo(2, this.form.lqType, value);
      }
    },
    // 公路等级切换，获取交通路段分类列表
    changeRoadLevel(value) {
      this.form.trafficType = undefined;
      this.form.weatherRegion = undefined;
      this.changeSelect();
      if (value) {
        this.lqmxeInfo(3, this.form.lqType, this.form.mxeType, value);
      }
    },
    // 交通路段分类切换，获取沥青气候分区列表
    changeTrafficType(value) {
      this.form.weatherRegion = undefined;
      this.changeSelect();
      if (value) {
        this.lqmxeInfo(
          4,
          this.form.lqType,
          this.form.mxeType,
          this.form.roadLevel,
          value
        );
      }
    },

    // 沥青信息
    lqInfo(type, asphaltNum, asphaltLevel) {
      lqInfo({
        trialNum: this.trialNum,
        lqType: this.$parent.$parent.$parent.$data.lqType,
        asphaltNum,
        asphaltLevel,
      })
        .then((res) => {
          let {
            data: { result },
          } = res;
          if (type == 1) {
            this.asphaltNumList = result || [];
            // if (this.select) {
            //   this.form.asphaltNum = this.asphaltNumList[0];
            //   this.changeAsphaltNum(this.form.asphaltNum);
            // }
          }
          if (type == 2) {
            this.asphaltLevelList = result || [];
            // if (this.select) {
            //   this.form.asphaltLevel = this.asphaltLevelList[0];
            //   this.changeAsphaltLevel(this.form.asphaltLevel);
            // }
          }
          if (type == 3) {
            this.weatherRegionList = result || [];
            // if (this.select) {
            //   this.form.weatherRegion = this.weatherRegionList[0];
            // }
          }
        })
        .catch((_) => {});
    },

    // 沥青等级切换，获取气候分区列表
    changeAsphaltLevel(value) {
      this.form.weatherRegion = undefined;
      this.changeSelect();
      if (!value) return;
      this.lqInfo(3, this.form.asphaltNum, value);
    },
    // 沥青类别切换，获取沥青等级列表
    changeAsphaltNum(value) {
      this.form.asphaltLevel = undefined;
      this.form.weatherRegion = undefined;
      this.changeSelect();
      if (value) {
        this.lqInfo(2, value);
      }
    },

    // 水泥品种切换，获取设计强度列表
    changeKind() {
      this.form.strengthGrade = undefined;
      if (!this.form.kind) {
        this.changeSelect();
      } else {
        snInfo({
          trialNum: this.trialNum,
          kind: this.form.kind,
        })
          .then((res) => {
            let {
              data: { result },
            } = res;
            this.designStrengthList = result || [];
            // if (this.select) {
            //   this.form.strengthGrade = this.designStrengthList[0];
            // }
            this.changeSelect();
          })
          .catch((_) => {});
      }
    },
    changeSelect() {
      this.$parent.$parent.$parent.getTableData();
    },
  },
};
</script>
<style lang="less" scoped></style>
